#ifndef HBHTTPCLIENT_H
#define HBHTTPCLIENT_H

#include <QJsonObject>
#include <QObject>
#include <QVariant>
#include <QVariantMap>

class HBHttpClient : public QObject {
  Q_OBJECT
public:
  explicit HBHttpClient(QObject *parent = nullptr);

  enum HttpType {
    Get,
    Post,
    Form,
  };

  //设置接口参数
  void setHttpType(HttpType type);
  void setUrlStr(QString urlStr);
  void setHeaders(QMap<QString, QString> headers);
  void addHeader(QString key, QString value);
  void setParams(QVariantMap params);
  void addParam(QString key, QVariant value);
  void setTimeout(int timeoutSeconds);

  //开始进行接口请求，阻塞过程
  void resume();

  //获取接口的返回值
  //错误码
  int responseCode();
  //描述
  QString responseErrorString();
  //返回的数据体
  QJsonObject responseBody();
  //返回的二进制数据
  QByteArray responseData();

signals:

private:
  QByteArray m_queryBody();
  QByteArray m_postBody();

private:
  HttpType m_type = Get;
  QString m_urlStr;
  QMap<QString, QString> m_headers;
  QVariantMap m_params;
  int m_timeout = 5;

  int m_code;
  QString m_responseMsg;
  QJsonObject m_response;
  QByteArray m_responseByte;
};

#endif // HBHTTPCLIENT_H
